package com.situ.mall.controller;

import com.situ.mall.pojo.Admin;
import com.situ.mall.pojo.User;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.pojo.query.UserQuery;
import com.situ.mall.service.IAdminService;
import com.situ.mall.service.IUserService;
import com.situ.mall.util.PageResult;
import com.situ.mall.util.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class

UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/list")
    public PageResult<User> list(UserQuery userQuery){
        PageResult<User> pageResult = userService.list(userQuery);
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        userService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(Integer[] ids){
        userService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(User user){
        userService.add(user);
        return Result.ok("添加成功");
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Integer id,Integer status,HttpSession session){
        Admin admin = (Admin) session.getAttribute("admin");
        if(admin==null||admin.getRole()==1){
            return Result.error("您没有权限");
        }
        System.out.println("status----------------"+status);
        userService.updateStatus(id,status);
        return Result.ok("更新成功");
    }
}
